package design.action.mediator;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zxs
 * @since 2020/05/27
 */
public class ConcreteMediator implements Mediator {

    private final ConcurrentHashMap<String,Colleague> cache = new ConcurrentHashMap<>();

    @Override
    public void sendMessage(String msg,Colleague colleague) {
        cache.values().stream().filter(c->!c.equals(colleague)).forEach(c->c.getMessage(msg));
    }

    @Override
    public void sendMessage(String target, String msg) {
        if(cache.containsKey(target)){
            cache.get(target).getMessage(msg);
        }
    }

    public void register(String key,Colleague colleague){
        cache.put(key,colleague);
    }
}
